﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

namespace SimulChess
{
    public partial class Main : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Game game = new Game();


            ChessPiece selectedPiece = game.FindPieceAtPosition(3, 7);
            bool[,] moves = null;

            if (selectedPiece != null)
                moves = selectedPiece.ShowMoves(game.Board);

            for (int y = 0; y < 8; y++)
            {
                var row = new TableRow();

                for (int x = 0; x < 8; x++) 
                {
                    var cell = new TableCell();

                    cell.ForeColor = Color.Gray;
                    cell.Font.Bold = true;
                    cell.Width = 40;
                    cell.Height = 40;

                    cell.Text = "";

                    if (game.Board.Position[x, y].Occupied)
                    {
                        ChessPiece piece = game.FindPieceAtPosition(x, y);
                        cell.Text = String.Format("{0}\n{1}", piece.Color.ToString(), piece.Name.ToString());
                    }
                    
                    if (game.Board.Position[x,y].BlockColor == PieceColor.white)
                        cell.BackColor = Color.White;
                    else
                        cell.BackColor = Color.Black;

                    if ((moves != null) && (moves[x, y]))
                    {
                        cell.BackColor = Color.Purple;
                    }

                    row.Cells.Add(cell);
                }
                
                this.Table1.Rows.Add(row);
            }
        }
    }
}